﻿using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
using MEF_Test.Bricks;
using MEF_Test.Bricks.Mediator;
using MEF_Test.Contracts;
using MEF_Test.Module.AudioStation.Properties;
using Microsoft.Practices.Unity;
using Synology.AudioStationApi;

namespace MEF_Test.Module.AudioStation
{
    [Export(typeof(IModuleThumbnail))]
    public class AudioStationThumbnail : IModuleThumbnail
    {
        public AudioStationThumbnail()
        {

            ModuleActivationCommand = new ParameterlessCommand(InitializeModule, () => true);
            Caption = "Synology AudioStation";
        }

        private void InitializeModule()
        {
            var syno = new AudioStationSession(Settings.Default.SynoHost, Settings.Default.SynoPort, Settings.Default.Login, Settings.Default.Password);
            // TODO : Do it in the background
            syno.Login(Settings.Default.Login, Settings.Default.Password);
            IoC.Current.RegisterInstance(typeof(IAudioStationSession),syno);

            Mediator<LoadModuleMediation>.Publish(new LoadModuleMediation
                                                      {
                                                          ModuleUri = new Uri("/Mef-Test.Module.AudioStation;component/AudioStationMain.xaml", UriKind.Relative)
                                                      });
        }

        public ICommand ModuleActivationCommand { get; set; }
        public string Caption { get; set; }
    }
}
